/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.unilearn.universitystaff;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author DidierLeung
 */
@Stateless
public class UniversityStaffSessionBean implements UniversityStaffSessionRemote
{
    @PersistenceContext
    EntityManager em;

    public void addStaff(UniversityStaff us)
    {
        UniversityStaffEntity aStaffEntity = new UniversityStaffEntity();
        aStaffEntity.setUniversityStaffEntityData(us);
        em.persist(aStaffEntity);
    }

    public List<UniversityStaff> getAllUniversityStaffs()
    {
        List<UniversityStaff> results = new ArrayList<UniversityStaff>();
        Query allStaffsQuery = em.createNamedQuery("findAllUniversityStaffs");
        List dbResults = allStaffsQuery.getResultList();
        for (int i = 0; i < dbResults.size(); i++)
        {
            UniversityStaffEntity aStaffEntity = (UniversityStaffEntity) dbResults.get(i);
            results.add(aStaffEntity.getUniversityStaffObject());
        }
        return results;
    }

    public UniversityStaff getUniversityStaff(String id)
    {
        UniversityStaffEntity aStaffEntity = em.find(UniversityStaffEntity.class, id);
        return aStaffEntity.getUniversityStaffObject();
    }
}
